<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目代建费用汇总表</title>
<link  rel="stylesheet" type="text/css" href="../css/ostrich/tab.css" />
   <%@include file="/view/resource.jsp" %>
</head>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript">
 	function openty(){
 		$("#edit-win").dialog('open');
 	}
 	function closety(){
 		$("#edit-win").dialog('close');
 	}
 	
 	function formsub(){
 		var test=document.getElementById("pctType").value;
 		var testText=document.getElementById("pctName").value;
 		var pspjid = document.getElementById("pjId").value;
 		
 			if(test==66||test==67||test==65){
 				if(testText==null||testText==''||testText==undefined)
	 				alert("请输入费用名称！");
	 			else
 					gertpubsupport(pspjid,test,testText);
	 		}else if(test!=66 && test!=67 && test!=65 && test!=''){
	 			if(testText==null||testText==''||testText==undefined)
	 				alert("请输入费用名称！");
	 			else
	 				document.editForm.submit();
	 		}
	 		else{
	 			alert("请选择需要生成的“费用类型”，再点击下一步。");
	 		}
 	}
 	
 	function gertpubsupport(pspjid,pcttype,pctname){
		$.ajax({
				url:"setPubsupport.do",
				type:"post",
				async:false,
				dataType:'json',
				data:{pjId:pspjid,pctType:pcttype},
				success:function (result){
					if(result.success){
						if(confirm(result.msg)){
							addPubsupport(pspjid,pctname,pcttype);
						}
					}
				}
		});
	 }
	 
	 function addPubsupport(pspjid,pspctName,pcttype){
	 	$.ajax({
				url:"addPubsupport.do",
				type:"post",
				async:false,
				dataType:'json',
				data:{pjId:pspjid,pctName:pspctName,pctType:pcttype},
				success:function (result){
					if(result.success){
						alert(result.msg);
						location.href=urls['msUrl']+"tostPjCostitem/list.do?pjId="+pspjid;
					}
				}
		});
	 }
	 
 	function delecost(id,pctType,pspjid){
 		if(confirm("您确认删除该预算项目，也将删除具体的项目内容。")){
 		  if(confirm("删除后将不能恢复，是否真的确认删除。")){
 			$.ajax({
				url:"deleteByid.do",
				type:"post",
				dataType:'json',
				data:{id:id,pctType:pctType},
				success:function (result){
					if(result.success){
						alert(result.msg);
						location.href="list.do?pjId="+pspjid;
					}
				}
			});
		   }
		}
 	}
 	
</script>
<body>
<table width="818" height="auto" align="center" >
<tr><td>
  <table width="807" height="auto" cellspacing="1" cellpadding="2" border="0" align="center" >
  <tr>
    <td colspan="8" bgcolor="#E7E7E7">${pjtab.pjProjectname}项目代建费用预算汇总表
    </td>
    </tr>
  <tr class='tabhead'>
 	 <th width="114">项目费用类型</th>
    <th width="114">费用项目</th>
    <th width="89">基础部分</th>
    <th width="83">奖励部分</th>
    <th width="119">金额（单位：元）</th>
     <th width="116">实际支出</th>
    <th width="117">备注</th>
    <th width="133">操作</th>
  </tr>
<c:forEach items="${list}" var="dataList">  
    <tr>
   	 <td width="89">${cmps[dataList.pctType].paName }</td>
      <td width="89">${dataList.pctName}</td>
      <td width="83">${dataList.pctBudget}</td>
      <td width="119">${dataList.pctPraise}</td>
      <td width="140">${dataList.pctTotal}</td>
       <td width="117">${dataList.pctFact}</td>
      <td width="133">${dataList.pctDesc}</td>
      <td width="114">
    <%--   <c:if test="${dataList.pctType }==66"></c:if> --%>
    <c:choose>
    	<c:when test="${dataList.pctType ==65||dataList.pctType ==66||dataList.pctType ==67}">
    		<a href="javascript:void();" onclick="gertpubsupport(${dataList.pjId},${dataList.pctType},'${dataList.pctName}')">重新生成</a>
    	</c:when>
    	<c:otherwise>
    		<a href="<%=request.getContextPath() %>${cmps[dataList.pctType].paValue }?pjId=${dataList.pjId}&pctId=${dataList.id}">编辑</a>
    	</c:otherwise>
    </c:choose>
    <a href="javascript:void();" onclick="delecost(${dataList.id},${dataList.pctType},${dataList.pjId })">删除</a>
      </td>
      </tr>
</c:forEach>
    <tr> <td colspan="8" align="right">
    <input type="button" value="返回" onclick="javascript:location.href='<%=request.getContextPath() %>/tostPjLookDetailsinfo/cost.do'">
    <input type="button" value="添加" onclick="openty()">
    </td></tr>
</table>
</td></tr>
<tr height="500px"><td><div id="edit-win" class="easyui-dialog" top="200px" title="添加提成项目步骤" data-options="closed:true,iconCls:'icon-save',modal:true"  style="width:500px;height:155px;">  
     	<form name="editForm" action="save.do" method="post">
     	 <!-- 隐藏文本框 -->
     	 <input class="hidden" name="id">
     	 <input class="hidden" name="deleted">
    	 <input class="hidden" name="parentId" id='edit_parentId'>
     	 <input class="hidden" name="pjId" id="pjId" value="${pjtab.id}">
	            <div data-options="region:'north',split:true" style="height:155px;padding:10px">  
	              <div class="fitem">  
	              <label>费用类型:</label>  
		               <select id="pctType" name="pctType" data-options="required:true" data-options="width:135">
		               <option></option>
		               <c:forEach items="${cmps }" var="cp">
							<option value="${cp.value.id }">${cp.value.paName }</option>               	
		               </c:forEach>
                   	</select>
		           </div>
		           <div class="fitem">
	              <label>费用名称:</label>
	              	<input type="text" id="pctName" name="pctName">
	              	</div>
		           <br><br>
		           <input type="button" id="next" value="下一步" algin="center" onclick="formsub()">   
		            <input type="button" value="取消" onclick="closety()" >
		     </div>
     	</form>
  	 </div></td></tr>
</table>
</body>
</html>
